package vip.xiaonuo.biz.modular.banner.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import vip.xiaonuo.biz.modular.banner.entity.BizBanner;
import vip.xiaonuo.biz.modular.banner.param.BizBannerAddParam;
import vip.xiaonuo.biz.modular.banner.param.BizBannerEditParam;
import vip.xiaonuo.biz.modular.banner.param.BizBannerIdParam;
import vip.xiaonuo.biz.modular.banner.param.BizBannerPageParam;
import vip.xiaonuo.biz.modular.banner.service.BizBannerService;
import vip.xiaonuo.common.annotation.CommonLog;
import vip.xiaonuo.common.pojo.CommonResult;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * Banner控制器
 *
 * @author SNOWY_TEAM
 **/
@Api(tags = "Banner管理")
@RestController
@Validated
@RequestMapping("/biz/banner")
public class BizBannerController {

    @Resource
    private BizBannerService bizBannerService;

    /**
     * 获取Banner分页列表
     *
     * @param bizBannerPageParam 查询参数
     * @return Banner分页列表
     */
    @ApiOperation("获取Banner分页列表")
    @GetMapping("/page")
    public CommonResult<Page<BizBanner>> page(BizBannerPageParam bizBannerPageParam) {
        return CommonResult.data(bizBannerService.page(bizBannerPageParam));
    }

    /**
     * 添加Banner
     *
     * @param bizBannerAddParam 添加参数
     * @return 添加结果
     */
    @ApiOperation("添加Banner")
    @CommonLog("添加Banner")
    @PostMapping("/add")
    public CommonResult<String> add(@RequestBody @Valid BizBannerAddParam bizBannerAddParam) {
        bizBannerService.add(bizBannerAddParam);
        return CommonResult.ok();
    }

    /**
     * 编辑Banner
     *
     * @param bizBannerEditParam 编辑参数
     * @return 编辑结果
     */
    @ApiOperation("编辑Banner")
    @CommonLog("编辑Banner")
    @PostMapping("/edit")
    public CommonResult<String> edit(@RequestBody @Valid BizBannerEditParam bizBannerEditParam) {
        bizBannerService.edit(bizBannerEditParam);
        return CommonResult.ok();
    }

    /**
     * 删除Banner
     *
     * @param bizBannerIdParam Banner ID参数
     * @return 删除结果
     */
    @ApiOperation("删除Banner")
    @CommonLog("删除Banner")
    @PostMapping("/delete")
    public CommonResult<String> delete(@RequestBody @Valid BizBannerIdParam bizBannerIdParam) {
        bizBannerService.delete(bizBannerIdParam);
        return CommonResult.ok();
    }

    /**
     * 获取Banner详情
     *
     * @param bizBannerIdParam Banner ID参数
     * @return Banner详情
     */
    @ApiOperation("获取Banner详情")
    @GetMapping("/detail")
    public CommonResult<BizBanner> detail(@Valid BizBannerIdParam bizBannerIdParam) {
        return CommonResult.data(bizBannerService.detail(bizBannerIdParam));
    }
} 